package oj;

public class LC151 {
    //1.使用倒序遍历拼接字符串
    public String reverseWords(String s) {
        s.trim();
        int j=s.length()-1;
        int i=j;
        StringBuilder sb=new StringBuilder();
        while(i>=0){
            while(i>=0 && s.charAt(i)!=' ') i--;
            sb.append(s.substring(i+1,j+1)+" ");
            while(i>=0 &&s.charAt(i)==' ') i--;
            j=i;
        }
        return sb.toString().trim();

    }
}
